<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"
	xmlns:hmrDetail="http://java.sun.com/jsf/composite/detail"	>

<cc:interface>
	<cc:attribute name="handler"				type="com.hemerasolutions.v2trainer.component.interfaces.search.ExerciseGroupSearchCompInterface" required="true"/>
	<cc:attribute name="onSearchComplete"		type="java.lang.String" 	default="" 				required="false"/>
	<cc:attribute name="searchUpdate"			type="java.lang.String" 	default="" 				required="false"/>
	<cc:attribute name="update"					type="java.lang.String" 	default=""				required="false"/>
	<cc:attribute name="showResultsPanel"		type="java.lang.Boolean"	default="false"			required="false"/>			
</cc:interface>

<cc:implementation>
	<span id="#{cc.clientId}" >
		<h:form id="findExerciseGroupForm" prependId="false" style="width:500px">
			<h:panelGrid columns="2">
				<h:outputLabel 	value="#{msgs.Name} :" 	/>
				<p:inputText	value="#{ cc.attrs.handler.exerciseGroupFindByName}" 			maxlength="50" 	size="20" />

				<h:outputLabel 	value="#{msgs.Description} :" />
				<p:inputText	value="#{ cc.attrs.handler.exerciseGroupFindByDescription}"	maxlength="100" 	size="45" />
 

				<h:outputLabel 	value="#{msgs.Obs} :"/>
				<p:inputText	value="#{ cc.attrs.handler.exerciseGroupFindByObs}"					maxlength="100" 	size="45" />

				<h:outputText value="#{msgs.ModalityTypes}" style="white-space: nowrap;"/>
				<p:selectCheckboxMenu value="#{cc.attrs.handler.findExerciseGroupByTrainingTypes}" converter="#{genericConverter}"   
					filter="true" panelStyle="width:220px" label="#{msgs.ModalityTypes}" >
	            	<f:selectItems value="#{cc.attrs.handler.fullTrainingTypes}"  var="trainingType" itemLabel="#{msgs[trainingType.name]}" itemValue="#{trainingType}" />
					<p:ajax event="toggleSelect"	listener="#{cc.attrs.handler.changeFullTrainingTypesAll}" update="egmodalitySelect"  />
					<p:ajax listener="#{cc.attrs.handler.changeFullTrainingTypes}" update="egmodalitySelect"  />
				</p:selectCheckboxMenu>

				<h:outputText  value="#{msgs.Modalitys}" />
				<p:selectCheckboxMenu id="egmodalitySelect" value="#{cc.attrs.handler.findExerciseGroupByModalitys}" converter="#{genericConverter}" 
					filter="true" panelStyle="width:220px" label="#{msgs.Modalitys}" disabled="#{empty cc.attrs.handler.fullModalitys }" >
					<p:ajax event="toggleSelect"	listener="#{cc.attrs.handler.changeFullModalitysAll}" update="egmodalitySelect"  />
	            	<f:selectItems value="#{cc.attrs.handler.fullModalitys}"  var="modality" itemLabel="#{modality.name}" itemValue="#{modality}" />
				</p:selectCheckboxMenu>		

				<h:outputLabel	value="#{ msgs.CreatedAt} :" />
				<h:column>
					<p:calendar		value="#{cc.attrs.handler.exerciseGroupBegCreatedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                	<p:calendar		value="#{cc.attrs.handler.exerciseGroupEndCreatedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>


				<h:outputLabel	value="#{ msgs.ChangedAt} :" />
				<h:column>
					<p:calendar		value="#{cc.attrs.handler.exerciseGroupBegChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true" readOnlyInputText="true"  />
                      #{ msgs.To}
                    <p:calendar		value="#{cc.attrs.handler.exerciseGroupEndChangedAt}"		locale="pt"		timeZone="Brazil/East" selectOtherMonths="true"	readOnlyInputText="true" />
				</h:column>

				<h:outputLabel value="#{ msgs.Status}  :" />
				<p:selectOneRadio value="#{ cc.attrs.handler.exerciseGroupFindByStatus}">
					<f:selectItem itemLabel="#{ msgs.Active}" 		itemValue="true" />
					<f:selectItem itemLabel="#{ msgs.Inactive}" 	itemValue="false" />
				</p:selectOneRadio>
			</h:panelGrid>
				
			<p:commandButton value="#{ msgs.Search}"	actionListener="#{cc.attrs.handler.searchExerciseGroups}" update=":growl, panelFoundExerciseGroupsTable" 	icon=" ui-icon-search"  process="@form" />
			<p:commandButton value="#{ msgs.Clear}"		type="button"	icon="ui-icon-clean">
				 <p:ajax update="findExerciseGroupForm" resetValues="true" />  	
			</p:commandButton>
			
			<p:outputPanel id="panelFoundExerciseGroupsTable" layout="block" rendered="#{cc.attrs.showResultsPanel}" >
				<p:spacer height="20" rendered="#{not empty cc.attrs.handler.foundedVersionableExerciseGroups }" />
				<p:dataTable id="tblExercisesGroup"  value="#{cc.attrs.handler.foundedVersionableExerciseGroups}" var="versionableExerciseGroup" paginator="true" rendered="#{not empty cc.attrs.handler.foundedVersionableExerciseGroups }"
					paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8">
					<p:columnGroup type="header">  
						<p:row>
							<p:column colspan="5">
								<f:facet name="header">
									<h:outputText value="#{msgs.ExerciseGroups}" />
								</f:facet>
							</p:column>
						</p:row>
						<p:row>
							<p:column	colspan="4"  style="white-space: nowrap;"  >
								<f:facet name="header">
									<h:outputText value="#{msgs.Name}"/>
								</f:facet>
							</p:column>
							<p:column	colspan="1" >
								<f:facet name="header">
									<h:outputText value="#{msgs.Description}"/>
								</f:facet>
							</p:column>
						</p:row>	
					</p:columnGroup>

					
					<p:column colspan="1" style="white-space: nowrap;">
						<h:outputText value="#{versionableExerciseGroup.exerciseGroup.name}"  />
					</p:column>
					<p:column colspan="1" style="white-space: nowrap;">
						<h:outputText value="#{versionableExerciseGroup.exerciseGroup.name}"  />
					</p:column>
					
					<p:column colspan="1" styleClass="ui-table-button-row" >
						<p:commandButton title="#{msgs.View}" icon="ui-icon-search" action="#{cc.attrs.handler.toViewExerciseGroup}" 	
							update=":#{cc.clientId}:modalExerciseGroupView" oncomplete="wmodalExerciseGroupView_#{cc.id}.show();"  styleClass="ui-table-button">
							<f:setPropertyActionListener target="#{cc.attrs.handler.exerciseGroup}" 	value="#{exerciseGroup}"/>
						</p:commandButton>	
					</p:column>
					<p:column colspan="1" styleClass="ui-table-button-row" >
						<p:commandButton title="#{msgs.Add}" icon="ui-icon-plus" action="#{cc.attrs.handler.addExerciseGroup}"  	
							update="#{cc.attrs.update},@form:panelFoundExerciseGroupsTable" oncomplete="#{cc.attrs.oncomplete}"  styleClass="ui-table-button" >
							<f:setPropertyActionListener target="#{cc.attrs.handler.selExerciseGroup}" 	value="#{exerciseGroup}"/>
						</p:commandButton>
					</p:column>		
					<p:column colspan="1" style="white-space: nowrap;width:300px;max-width:300px;">
						<h:outputText value="#{exerciseGroup.description}"  />
					</p:column>

				</p:dataTable>
			</p:outputPanel>	
		</h:form>		
	</span>

	<p:dialog id="modalExerciseGroupView" header="#{msgs.ExerciseGroup}: #{cc.attrs.handler.selExerciseGroup.name}" appendTo="@(body)" modal="true" widgetVar="wmodalExerciseGroupView_#{cc.id}" >
		<hmrDetail:exerciseGroupDetails handler="#{cc.attrs.handler.exerciseGroupDetails}"/>
	</p:dialog>	

</cc:implementation>
</html>	